Update database schema
authorJeroen van der Heijden <jeroen@transceptor.technology>
Fri, 6 Apr 2018 09:15:58 +0000 (11:15 +0200)
committerJeroen van der Heijden <jeroen@transceptor.technology>
Fri, 6 Apr 2018 09:15:58 +0000 (11:15 +0200)
include/siri/db/db.h
src/siri/db/db.c
src/siri/db/shard.c

index f63ad4672f91044263443419848e0f56e1fe45da..e75a10e192ac3051bb3b5302d33cdd61f311efdb 100644 (file)
@@ -31,7 +31,7 @@
 
 #define SIRIDB_MAX_SIZE_ERR_MSG 1024
 #define SIRIDB_MAX_DBNAME_LEN 256  // 255 + NULL
-#define SIRIDB_SCHEMA 2
+#define SIRIDB_SCHEMA 3
 #define SIRIDB_FLAG_REINDEXING 1
 
 #define DEF_DROP_THRESHOLD 1.0              // 100%
index fa93189785c97486e3dfb1ba48443a939786b76a..6b6a99e7467c5f787c6b93abd4831065f85db623 100644 (file)
@@ -368,7 +368,7 @@ static int SIRIDB_from_unpacker(
     }
 
     /* check schema */
-    if (qp_schema.via.int64 == 1)
+    if (qp_schema.via.int64 == 1 || qp_schema.via.int64 == 2)
     {
         log_info(
                 "Found an old database schema (v%d), "
index 03fc0d776900913c0e9086b6cdad650aba40847f..801e3e486e33d83bd1b4c7ae757a41634d7dddd5 100644 (file)
@@ -40,7 +40,7 @@
 #define SHARD_GROW_SZ 131072
 
 /* shard schema (schemas below 20 are reserved for Python SiriDB) */
-#define SIRIDB_SHARD_SHEMA 20
+#define SIRIDB_SHARD_SHEMA 21
 
 /*
  * Header schema layout
@@ -208,6 +208,17 @@ int siridb_shard_load(siridb_t * siridb, uint64_t id)
         return -1;
     }
 
+    uint8_t schema = (uint8_t) header[HEADER_SCHEMA];
+    if (schema > SIRIDB_SHARD_SHEMA)
+    {
+        fclose(fp);
+        log_critical(
+                "Shard file '%s' has schema '%u' which is not supported with "
+                "this version of SiriDB.", shard->fn, schema);
+        siridb_shard_decref(shard);
+        return -1;
+    }
+
     /* set shard type, flags and max_chunk_sz */
     shard->tp = (uint8_t) header[HEADER_TP];
     shard->flags = (uint8_t) header[HEADER_FLAGS] | SIRIDB_SHARD_IS_LOADING;